package com.example.listviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddContact extends AppCompatActivity implements View.OnClickListener {


    private EditText editname;
    private EditText editphone;
    private EditText editemail;
    private Button cancel;
    private Button confirm;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
                finish();
                break;
            case R.id.btn_confirm:
                Contact contact = new Contact();
                contact.setName(editname.getText().toString());
                contact.setPhone(editphone.getText().toString());
                contact.setEmail(editemail.getText().toString());
                contact.save();
                Toast.makeText(AddContact.this,"保存成功",Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_contact);
        editname = findViewById(R.id.edit_name);
        editphone = findViewById(R.id.edit_phone);
        editemail = findViewById(R.id.edit_email);
        cancel = findViewById(R.id.btn_cancel);
        confirm = findViewById(R.id.btn_confirm);
        editname.setOnClickListener(this);
        editphone.setOnClickListener(this);
        editemail.setOnClickListener(this);
        cancel.setOnClickListener(this);
        confirm.setOnClickListener(this);
    }
}
